<template>
<div class="recycle-categories views-container">
    <div class="wlm-table">
        <div class="wlm-table-header">
            <el-form :model="tableFormatData.userTable.files" size="small" label-width="80px" class="retail-form" label-position="right">
                <el-form-item label="分类名称：" class="search">
                    <el-input v-model="tableFormatData.userTable.files.name" placeholder="请输入分类名称" style="width:160px;"></el-input>
                </el-form-item>
                <el-form-item label="" class="filter-btns">
                    <el-button type="primary" @click="filesSerch">筛选</el-button>
                    <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="wlm-table-content">
            <el-table :ref="tableFormatData.userTable.key" :data="filterTable" @selection-change="handleSelectionChange" style="width: 100%">
                <el-table-column type="selection" width="55">
                </el-table-column>
                <el-table-column prop="date" label="分类名称" align="left">
                    <template slot-scope="scope">
                        <!-- <router-link tag="span" :to="{path:'/user/managementUserEdit', query:{id:scope.row.id}}">
                            <span class="pointer">{{scope.row.name}}</span>
                        </router-link> -->
                        <span v-if="scope.row.parent_id>0">&nbsp;&nbsp;&nbsp;&nbsp;--{{scope.row.name}}</span>
                        <span v-else>{{scope.row.name}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="分类图片" >
                    <template slot-scope="scope">
                        <img v-if="scope.row.image" class="logo" :src="scope.row.image.file_path">
                        <span v-else>--</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="商品数量" >
                    <template slot-scope="scope">
                        <span v-if="scope.row.parent_id === 0">{{scope.row.goodsnum}}</span>
                        <span v-if="scope.row.parent_id > 0">{{scope.row.goodsnum}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="状态" >
                    <template slot-scope="scope" v-if="scope.row.status === 0 || scope.row.status === 1">
                        <span>{{scope.row.status=='1'?'开启':'关闭'}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="排序" >
                    <template slot-scope="scope">
                        <span>{{scope.row.sort}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" >
                    <template slot-scope="scope">
                        <div class="operation-group">
                            <el-button class="wlm-text" type="text" @click="changeTableItem({ids:[scope.row.category_id],type:'goods_cate'},tableFormatData.userTable.change.restore)">恢复</el-button>
                            <div class="btn-line"></div>
                            <el-button class="wlm-text" type="text" @click="delTableItem(scope.row.id)">删除</el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-content flex-row flex-justify-b flex-align-c">
                <el-row class="pagination-btns">
                    <el-checkbox class="check-all" true-label="1" false-label="0" v-model="tableFormatData.userTable.files.checkall" @change="toggleSelection">全部</el-checkbox>
                    <el-button class="right-8" type="primary" :disabled="isGroup" size="mini" @click="changeTableItem({isGroup:true,type:'goods_cate'},tableFormatData.userTable.change.restore)">批量恢复</el-button>
                    <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">删除</el-button>
                </el-row>
                <!-- <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
                </el-pagination> -->
            </div>
        </div>
    </div>
</div>
</template>

<script>
import {
  getDelGoodsClassList,
  recoveryDeletedInfo,
  deleteThoroughlyInfo
} from '@/api/recycle'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table')],
  name: 'RecycleCategories',
  components: {

  },
  computed: {
    filterTable() {
      const tableData = this.tableFormatData.userTable.tableData
      const tableDataArr = Object.keys(tableData)
      const result = []
      if (Array.isArray(tableDataArr)) {
        tableDataArr.map((item, index) => {
          result.push(tableData[item])
          //   console.log(tableData[item])
          if (Array.isArray(tableData[item]['child'])) {
            // console.log(tableData[item]['child'], 'item.child')
            tableData[item]['child'].map((childItem, childIndex) => {
              // tableData[item].goodsnum += childItem.goodsnum
              result.push(childItem)
            })
          }
        })
      }
      return result
    }
  },
  data() {
    return {
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: getDelGoodsClassList,
            delList: deleteThoroughlyInfo
          },
          tableData: {
            redirect: 'filterTable'
          },
          files: {
            name: '',
            ids: [],
            checkall: '0',
            redirect: 'category_id',
            type: 'goods_cate'
          },
          change: {
            restore: {
              name: '恢复',
              key: 'restore',
              api: recoveryDeletedInfo
            }
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  filters: {

  },
  methods: {
    changeTableCallBack(params) {

    }
  }
}
</script>

<style lang="scss" scoped>
.recycle-categories {
    .logo {
        height: 32px;
        width: 32px;
        border-radius: 32px;
        vertical-align: middle;
    }
}
</style>
